module.exports = {
  up: async (queryInterface, Sequelize) => {
    // 1. 表格配置表
    await queryInterface.createTable('table_configs', {
      id: {
        type: Sequelize.UUID,
        defaultValue: Sequelize.UUIDV4,
        primaryKey: true,
      },
      code: {
        type: Sequelize.STRING(100),
        allowNull: false,
        unique: true,
        comment: '表格唯一标识',
      },
      name: {
        type: Sequelize.STRING(100),
        allowNull: false,
        comment: '表格名称',
      },
      description: {
        type: Sequelize.TEXT,
        allowNull: true,
        comment: '表格说明',
      },
      api_url: {
        type: Sequelize.STRING(255),
        allowNull: true,
        comment: 'API接口地址',
      },
      default_page_size: {
        type: Sequelize.INTEGER,
        allowNull: false,
        defaultValue: 20,
        comment: '默认每页条数',
      },
      enable_search: {
        type: Sequelize.BOOLEAN,
        allowNull: false,
        defaultValue: true,
        comment: '是否启用搜索',
      },
      enable_export: {
        type: Sequelize.BOOLEAN,
        allowNull: false,
        defaultValue: false,
        comment: '是否启用导出',
      },
      enable_selection: {
        type: Sequelize.BOOLEAN,
        allowNull: false,
        defaultValue: false,
        comment: '是否启用多选',
      },
      table_height: {
        type: Sequelize.INTEGER,
        allowNull: true,
        comment: '表格高度',
      },
      is_active: {
        type: Sequelize.BOOLEAN,
        allowNull: false,
        defaultValue: true,
        comment: '是否启用',
      },
      sort_order: {
        type: Sequelize.INTEGER,
        allowNull: false,
        defaultValue: 0,
      },
      created_at: {
        type: Sequelize.DATE,
        allowNull: false,
      },
      updated_at: {
        type: Sequelize.DATE,
        allowNull: false,
      },
    });

    await queryInterface.addIndex('table_configs', ['code']);
    await queryInterface.addIndex('table_configs', ['is_active']);
  },

  down: async (queryInterface) => {
    await queryInterface.dropTable('table_configs');
  },
};

